function validate(evt) {
                var theEvent = evt || window.event;
                var key = theEvent.keyCode || theEvent.which;
                key = String.fromCharCode( key );
                var regex = /[0-9]|\./;
                if( !regex.test(key) ) {
                    theEvent.returnValue = false;
                    if(theEvent.preventDefault) theEvent.preventDefault();
                }
}

function updateField(name, a_name) {
                formName = document.forms['fillupform'];
                formElement = formName.elements[name].value;
                formName.elements[a_name].value = (formElement*formName.elements['loanamt'].value)/100;
                
                
}

function updatevat(name, a_name) {
                formName = document.forms['fillupform'];
                formElement = formName.elements[name].value;
                formName.elements[a_name].value = (formElement*formName.elements['ui'].value)/100;
                
}

function searchPrecomp(){
        document.location.href = 'SearchPrecompServlet'; 
}

function editRecord(id){
        document.location.href = 'EditAgentServlet?id='+id; 
}

function editTerm(id){
        document.location.href = 'EditTermServlet?id='+id; 
}

function deleteRecord(id){
        document.location.href = 'DeleteTypeServlet?id='+id; 
        
}

function selectPrecomp(precompno){
        document.location.href = 'SelectPrecompServlet?precompno='+precompno;
}

function selectLoan(loanno){
        document.location.href = 'SelectLoanServlet?loanno='+loanno;
}

function updateAgentCode(){
                formName = document.forms['loanentryform'];
                elementIndex = formName.elements['agentname'].selectedIndex;
                formName.elements['agentcode'].value = formName.elements['hiddenagentcode'].options[elementIndex].text;
}

function updateUserID(){
                formName = document.forms['approveuserform'];
                elementIndex = formName.elements['username'].selectedIndex;
                formName.elements['userID'].value = formName.elements['hiddenuserid'].options[elementIndex].text;
}

function calculatePrecomp(){
                document.fillupform.action="Fillup";
}
function savePrecomp(){
                
                formName = document.forms['fillupform'];
                if(formName.elements['firstname'].value==""||formName.elements['lastname'].value==""||formName.elements['middlename'].value==""||formName.elements['firstname'].value==null||formName.elements['lastname'].value==null||formName.elements['middlename'].value==null){
                    alert("Please enter borrower details");
                    
                }else{
                    
                    document.fillupform.action="SavePrecomp";
                    document.forms['fillupform'].submit();
                }                
}

function tryPrecomp(){
                
                formName = document.forms['fillupform'];
                if(formName.elements['firstname'].value==""||formName.elements['lastname'].value==""||formName.elements['middlename'].value==""||formName.elements['firstname'].value==null||formName.elements['lastname'].value==null||formName.elements['middlename'].value==null){
                    alert("Please enter borrower details");
                    return false;
                }else{
                    
                    document.fillupform.action="SavePrecomp";
                    document.forms['fillupform'].submit();
                    return true;
                }                
}

function searchLoan(){
    document.location.href = 'SearchLoanServlet'; 
}

function checkSoa(loanno){
    if(loanno==0){
        alert("Please Choose an Account");
    }else{
        document.location.href = 'addsoaentry.jsp?loanno='+loanno; 
    }
}
